<h1>Listing events</h1>

<table>
  <tr>
    <th>Event</th>
    <th>Author</th>
    <th>Date/Time</th>
    <th></th>
    <th></th>
    <th></th>
  </tr>

<% @events.each do |event| %>
  <tr>
    <td><%= event.name %></td>
    <td><%= event.author %></td>
    <td><%= event.starts_at.to_formatted_s(:long_ordinal) %></td>
    <td><%= link_to 'Show', event %></td>
	
	<% if session[:user].id == event.author_id %>
		<td><%= link_to 'Edit', edit_event_path(event) %></td>
	<% end %>
	
	<% if session[:user].authority == "admin" or session[:user].authority == "manager" or session[:user].id == event.author_id %>
		<td><%= link_to 'Destroy', event, :confirm => 'Are you sure?', :method => :delete %></td>
	<% end %>
	

  </tr>
<% end %>
</table>

<br />

<% if session[:user].authority != "user" %>
	<%= link_to 'New Event', new_event_path %>
<% end %>
<br>
<% if flash[:message] != nil %>
	<%= flash[:message] %>
<% end %>

<% if flash[:warning] != nil %>
	<%= flash[:warning] %>
<% end %>